package main

import (
	"encoding/json"
	"fmt"
	"math"
	"math/rand"
	"strconv"
	"time"
)



func main(){
	userName := strconv.Itoa(int(12345678))
	userName = "M"+ userName[0:5]
	fmt.Println("___", userName)


	robotList := []int32{1,2,3}
	list, id := RouletteGetRobotId(robotList)
	robotList = list
	fmt.Println(robotList, id)
	list, id = RouletteGetRobotId(list)
	robotList = list
	fmt.Println(list, id)
	list, id = RouletteGetRobotId(list)
	robotList = list
	fmt.Println(list, id)

	fmt.Println("__222222_", len(list), robotList)

	//test1()

	a := GetPrecision(3.55445555, 3)
	fmt.Println("__a", a)
	b := GetPrecision(a, 3)
	fmt.Println("__b", b)

	c := rounding(float64(b),3)
	fmt.Println("__c", c)



	//var robotList []int32
	//if len(robotList) == 0{
	//	robotList = []int32{}
	//	fmt.Println("___robotList__", len(robotList))
	//}
	//
	//
	//dir,_ := os.Getwd()
	//fmt.Println("当前路径：",dir)




}

//func RouletteGetRobotId(robotList []int32) ([]int32, int32){
//	if len(robotList) <= 0 {
//		return []int32{}, 0
//	}
//	num := 1
//	id := robotList[num]
//	robotList = append(robotList[:num], robotList[num+1:]...)
//	return robotList, id
//}

func test1(){
	//时间截转成日期
	currentTime := time.Now()
	timeTemplate3 := "2006-01-02"
	fmt.Println("_____", currentTime)

	for i:=29; i>=0; i--{
		oldTime := currentTime.AddDate(0, 0, -i)
		str := time.Unix(oldTime.Unix(), 0).Format(timeTemplate3)
		fmt.Println("___", str)
	}

}





//四舍五入取进度
func GetPrecision(value float32, precision int) float32 {
	if precision <= 0 {
		//取整数
		return float32(int32(value))
	} else if precision == 1 {
		//取1位小数
		operValue := float32(int32(value*10+0.5)) / float32(10)
		return operValue
	} else if precision == 2 {
		//取2位小数
		operValue := float32(int32(value*100+0.5)) / float32(100)
		return operValue
	} else if precision == 3 {
		//取3位小数
		operValue := float32(int32(value*1000+0.5)) / float32(1000)
		return operValue
	} else {
		//取4位小数
		operValue := float32(int32(value*10000+0.5)) / float32(10000)
		return operValue
	}
}

func rounding(num, digit float64) float64{
	num = num / digit
	if (num > 0.0001){
		return  float64(math.Floor(float64(num) + 0.5)) * digit
	}
	return float64(math.Ceil(float64(num) - 0.5) * digit)
}

//从列表中随机取一个uid
func RouletteGetRobotId(robotList []int32) ([]int32, int32){
	if len(robotList) <= 0 {
		return []int32{}, 0
	}
	rand.Seed(time.Now().UnixNano())
	totalNum := len(robotList)
	num := rand.Intn(totalNum)
	id := robotList[num]
	robotList = append(robotList[:num], robotList[num+1:]...)
	return robotList, id
}